$(function () {
    $("#search_begindate").simpleCanleder();
    $("body").trigger(".inner");

    $("body").on("click",".smk-xx",function(){
    	localStorage.hk=$(".kahao").text();
    	localStorage.kcp=$(".kaleixing").text();
    	localStorage.klx=$(".kachanping").text();
    	var now = new Date();
    $.ajax({
     url:"front/queryPersonalCardInfoAndConsumeRecordsByPaperNo.do",
     type:"POST",
     data: {userId:$("#userId").attr("uid"),citizenCardNo:$(this).attr("cardtype"),transactionType:0,appFlag:"1",year:now.getFullYear(),month:now.getMonth()+1},
     dataType:"JSON",
     success:function (json) {
         if (json.code==0){
        	 $(".xiaofeiTD").children().remove()
        	 $(".xflx").text("消费类型："+json.data[0].appName);
            var span = $(" <span>市民卡号："+localStorage.hk+"</span><span>市民卡产品："+localStorage.kcp+"</span><span>实名卡类型："+localStorage.klx+"</span>").appendTo(".k-xx");
             $(".zye").text(json.data[0].newBalance);
            $(".k-xx").attr("typeid",json.data[0].cardPCode);
            if(json.data[0].transactionRecords.length!==0){
            var zsr=0;
            var zzc=0;
                $(json.data[0].transactionRecords).each(function(i,o){
                    if (o.acTypeName=="充值"){
                    zsr=zsr+o.txnAmt;
                        var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>"+o.acTypeName+"</td><td>+"+o.txnAmt+"</td><td>"+o.creDate+"</td></tr>").appendTo(".xiaofeiTD");
                    }else{
                    zzc=zzc+o.txnAmt;
                        var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>"+o.acTypeName+"</td><td>-"+o.txnAmt+"</td><td>"+o.creDate+"</td></tr>").appendTo(".xiaofeiTD");
                    }

                })
                $(".zsr").text("收入：￥"+zsr);
                $(".zzc").text("支出：￥"+zzc);
            }else{
            var td = $("<tr><td colspan='4' style='text-align: center;font-size: 20px;color: #666666; margin: 200px 0;'><img src='/qzsmkweb/static/img/jycxerr.png' style='margin-right: 28px;'/>查询不到交易明细！</td></td></tr>").appendTo(".xiaofeiTD");
            }
         }else{
        	 alert(json.message)
         }
     }
    })
        $(".jiaoyika").css("display","none");
        $(".jyxiangqing").css("display","block");
     })
     
     $(".yyfl").click(function(){
    	 $(this).addClass("yyflxz").siblings().removeClass("yyflxz");
    	 if($("#search_begindate").val()!==""){
    		    var ym = $("#search_begindate").val().split("-");
    		    $.ajax({
    		        url:"front/queryCardByUser.do",
    		        type:"POST",
    		        data:{userId:$("#userId").attr("uid"),citizenCardNo:localStorage.hk,transactionType:0,appFlag:$(".yyfl.yyflxz").attr("zt"),year:ym[0],month:parseInt(ym[1])},
    		        dataType:"JSON",
    		        success:function (json) {
    		            if (json.code==0){
    		                $(".xiaofeiTD").children().remove();
    		                if (json.data[0].transactionRecords.length!==0){
    		                    var zsr=0;
    		                    var zzc=0;
    		                    $(json.data[0].transactionRecords).each(function(i,o) {
    		                        if (o.acTypeName == "充值") {
    		                            zsr=zsr+o.txnAmt;
    		                            var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>" + o.acTypeName + "</td><td>+" + o.txnAmt + "</td><td>" + o.creDate + "</td></tr>").appendTo(".xiaofeiTD");
    		                        } else {
    		                            zzc=zzc+o.txnAmt;
    		                            var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>" + o.acTypeName + "</td><td>-" + o.txnAmt + "</td><td>" + o.creDate + "</td></tr>").appendTo(".xiaofeiTD");
    		                        }
    		                    })
    		                    $(".zsr").text("收入：￥" + zsr);
    		                    $(".zzc").text("支出：￥" + zzc);
    		                }else{
    		                    var td = $("<tr><td colspan='4' style='text-align: center;font-size: 20px;color: #666666; margin: 200px 0;'><img src='/qzsmkweb/static/img/jycxerr.png' style='margin-right: 28px;'/>查询不到交易明细！</td></td></tr>").appendTo(".xiaofeiTD");
    		                }
    		            }else{
    		            	alert(json.message)
       	            	 $(".xiaofeiTD").children().remove()
    		            }
    		        }
    		    })	 
    	 }else{
    	    	var now = new Date();
    	        $.ajax({
    	         url:"front/queryPersonalCardInfoAndConsumeRecordsByPaperNo.do",
    	         type:"POST",
    	         data: {userId:$("#userId").attr("uid"),citizenCardNo:localStorage.hk,transactionType:0,appFlag:$(".yyfl.yyflxz").attr("zt"),year:now.getFullYear(),month:now.getMonth()+1},
    	         dataType:"JSON",
    	         success:function (json) {
    	             if (json.code==0){
    	            	 $(".xiaofeiTD").children().remove()
    	                var span = $(" <span>市民卡号："+localStorage.hk+"</span><span>市民卡产品："+localStorage.kcp+"</span><span>实名卡类型："+localStorage.klx+"</span>").appendTo(".k-xx");
    	                 $(".zye").text(json.data[0].newBalance);
    	                $(".k-xx").attr("typeid",json.data[0].cardPCode);
    	                if(json.data[0].transactionRecords.length!==0){
    	                var zsr=0;
    	                var zzc=0;
    	                    $(json.data[0].transactionRecords).each(function(i,o){
    	                        if (o.acTypeName=="充值"){
    	                        zsr=zsr+o.txnAmt;
    	                            var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>"+o.acTypeName+"</td><td>+"+o.txnAmt+"</td><td>"+o.creDate+"</td></tr>").appendTo(".xiaofeiTD");
    	                        }else{
    	                        zzc=zzc+o.txnAmt;
    	                            var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>"+o.acTypeName+"</td><td>-"+o.txnAmt+"</td><td>"+o.creDate+"</td></tr>").appendTo(".xiaofeiTD");
    	                        }

    	                    })
    	                    $(".zsr").text("收入：￥"+zsr);
    	                    $(".zzc").text("支出：￥"+zzc);
    	                }else{
    	                var td = $("<tr><td colspan='4' style='text-align: center;font-size: 20px;color: #666666; margin: 200px 0;'><img src='/qzsmkweb/static/img/jycxerr.png' style='margin-right: 28px;'/>查询不到交易明细！</td></td></tr>").appendTo(".xiaofeiTD");
    	                }
    	             }else{
    	            	 alert(json.message)
    	            	 $(".xiaofeiTD").children().remove()
    	             }
    	         }
    	        })
    	 }
     })
    getCard();

$("body").on("click",".inner",function () {
    var ym = $("#search_begindate").val().split("-");
    $.ajax({
        url:"front/queryCardByUser.do",
        type:"POST",
        data:{userId:$("#userId").attr("uid"),citizenCardNo:localStorage.hk,transactionType:0,appFlag:$(".yyfl.yyflxz").attr("zt"),year:ym[0],month:parseInt(ym[1])},
        dataType:"JSON",
        success:function (json) {
            if (json.code==0){
                $(".xiaofeiTD").children().remove();
                if (json.data[0].transactionRecords.length!==0){
                    var zsr=0;
                    var zzc=0;
                    $(json.data[0].transactionRecords).each(function(i,o) {
                        if (o.acTypeName == "充值") {
                            zsr=zsr+o.txnAmt;
                            var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>" + o.acTypeName + "</td><td>+" + o.txnAmt + "</td><td>" + o.creDate + "</td></tr>").appendTo(".xiaofeiTD");
                        } else {
                            zzc=zzc+o.txnAmt;
                            var tr = $("<tr><td class='imgtd'><img src='static/img/xflogo.png'/></td><td>" + o.acTypeName + "</td><td>-" + o.txnAmt + "</td><td>" + o.creDate + "</td></tr>").appendTo(".xiaofeiTD");
                        }
                    })
                    $(".zsr").text("收入：￥" + zsr);
                    $(".zzc").text("支出：￥" + zzc);
                }else{
                    var td = $("<tr><td colspan='4' style='text-align: center;font-size: 20px;color: #666666; margin: 200px 0;'><img src='/qzsmkweb/static/img/jycxerr.png' style='margin-right: 28px;'/>查询不到交易明细！</td></td></tr>").appendTo(".xiaofeiTD");
                }
            }else{
            	alert(json.message)
           	 $(".xiaofeiTD").children().remove()
            }
        }
    })
})

});

function getCard() {
    $.ajax({
        url:"front/queryCardProdunctByPersonal.do",
        type:"GET",
        dataType:"JSON",
        success:function(json){
           if(json.code==0){
             $(json.data).each(function(i,o){
                var div = $(" <div class='smk-xx' cardtype='"+o.citizenCardNo+"'><div class='k-xx'><div>市民卡号：<span class='kahao'>"+o.citizenCardNo+"</span></div><div>市民卡产品：<span class='kaleixing'>"+o.cardpName+"</span></div><div>市名卡类型：<span class='kachanping'>"+o.cardTypeName+"</span></div></div></div>").appendTo(".jiaoyika");
             })
           }else {
             var td = $("<div style='text-align: center;text-align: center;font-size: 20px;color: #666666; margin: 200px 0;'><img src='/qzsmkweb/static/img/jycxerr.png' style='margin-right: 28px;'/>系统未查询到您名下实名制市民卡交易信息，请先办理实名制卡后在查询！</div>").appendTo(".jiaoyika");
           }
        }
    })
}